(function (vc) {
    vc.extends({
        data: {
            prestoreAccountRefundInfo: {
                tel: '',
                ownerId: '',
                owners: [],
                amount: '',
                remark: '',
                acctType: '',
                acctId:'',
                feeConfigs:[],
                configId:'',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('prestoreAccountRefund', 'openAddModal', function () {
                $('#prestoreAccountRefundModel').modal('show');
            });

            vc.on('prestoreAccountRefund', 'openAddModalWithParams', function (_param) {
                vc.component.prestoreAccountRefundInfo.acctType ='2003';
                vc.component.prestoreAccountRefundInfo.ownerId = _param.ownerId;
                vc.component.prestoreAccountRefundInfo.acctId = _param.conditions.acctId;
                $('#prestoreAccountRefundModel').modal('show');
                $that.initFeeConfig();
            });
        },
        methods: {
            prestoreAccountRefundValidate() {
                return vc.validate.validate({
                    prestoreAccountRefundInfo: vc.component.prestoreAccountRefundInfo
                }, {
                    'prestoreAccountRefundInfo.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "退款金额不能为空"
                        },
                        {
                            limit: "money",
                            param: "",
                            errInfo: "金额格式错误"
                        },
                    ],
                    'prestoreAccountRefundInfo.configId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "退款指定费项不能为空"
                        },
                    ],
                    'prestoreAccountRefundInfo.remark': [
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "备注长度不能超过200位"
                        }
                    ]
                });
            },
            saveprestoreAccountRefundInfo: function () {
                if (!vc.component.prestoreAccountRefundValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.component.prestoreAccountRefundInfo.communityId = vc.getCurrentCommunity().communityId;
                vc.http.apiPost(
                    '/account/ownerRefundAccount',
                    JSON.stringify(vc.component.prestoreAccountRefundInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#prestoreAccountRefundModel').modal('hide');
                            vc.component.clearprestoreAccountRefundInfo();
                            //来源界面可能有两个，懒得传参了 一起刷新
                            vc.emit('simplifyAccountDetailManage', 'refresh', {});
                            vc.emit('accountDetailManage', 'refresh', {});
                            _data = _json.data;
                            vc.emit('payFeeOrderResult', '_loadReceipt', _data)
                            // vc.toast('退款成功');
                            return;
                        }
                        vc.toast(_json.msg);
                        // vc.component.prestoreAccountRefundInfo.errorInfo = _json.msg;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.component.prestoreAccountRefundInfo.errorInfo = errInfo;
                    });
            },
            clearprestoreAccountRefundInfo: function () {
                vc.component.prestoreAccountRefundInfo = {
                    tel: '',
                    ownerId: '',
                    owners: [],
                    amount: '',
                    remark: '',
                    acctId:'',
                    feeConfigs:[],
                    configId:'',
                };
            },
            initFeeConfig:function(){
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        communityId: vc.getCurrentCommunity().communityId,
                        ownerId: $that.prestoreAccountRefundInfo.ownerId,
                        type:"refund",
                    }
                };
                //发送get请求
                vc.http.apiGet('/fee.listFeeConfig',
                    param,
                    function (json) {
                        let _feeConfigInfo = JSON.parse(json);
                        vc.component.prestoreAccountRefundInfo.feeConfigs = _feeConfigInfo.fees;
                    },
                    function () {
                        console.log('请求失败处理');
                        vc.component.prestoreAccountRefundInfo.feeConfigs = [];s
                    }
                );
            }
        }
    });
})(window.vc);